import { IsString, IsOptional, IsNumber, Min, Max, IsNotEmpty, IsArray } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';
import { SearchDto } from '../../common/dto/pagination.dto';

export class CreateRoleDto {
  @IsString()
  @IsNotEmpty()
  name: string;

  @IsString()
  @IsNotEmpty()
  code: string;

  @IsString()
  @IsOptional()
  description?: string;

  @IsNumber()
  @IsOptional()
  @Min(0)
  @Max(1)
  status?: number = 1;

  @IsNumber()
  @IsOptional()
  sort?: number = 0;
}

export class UpdateRoleDto {
  @IsString()
  @IsOptional()
  name?: string;

  @IsString()
  @IsOptional()
  code?: string;

  @IsString()
  @IsOptional()
  description?: string;

  @IsNumber()
  @IsOptional()
  @Min(0)
  @Max(1)
  status?: number;

  @IsNumber()
  @IsOptional()
  sort?: number;
}

export class QueryRolesDto extends SearchDto {
  @ApiProperty({ description: '角色名精确搜索', required: false })
  @IsOptional()
  @IsString()
  name?: string;

  @ApiProperty({ description: '角色代码精确搜索', required: false })
  @IsOptional()
  @IsString()
  code?: string;

  @ApiProperty({ description: '状态筛选：1-启用，0-禁用', required: false })
  @IsOptional()
  @Type(() => Number)
  @Min(0)
  @Max(1)
  status?: number;
}

export class AssignPermissionsDto {
  @IsArray()
  @IsNumber({}, { each: true })
  @Type(() => Number)
  permissionIds: number[];
}

export class AssignMenusDto {
  @IsArray()
  @IsNumber({}, { each: true })
  @Type(() => Number)
  menuIds: number[];
}